import 'package:equatable/equatable.dart';

/// 浇水方式枚举
enum WateringMethod {
  rootDrenching('Root Drenching'),
  foliarSpraying('Foliar Spraying');

  const WateringMethod(this.displayName);
  final String displayName;
}

/// 肥料类型枚举
enum FertilizerType {
  nitrogen('Nitrogen fertilizer'),
  phosphorusPotassium('Phosphorus-Potassium Fertilizer'),
  compound('Compound Fertilizer'),
  organic('Organic Fertilizer');

  const FertilizerType(this.displayName);
  final String displayName;
}

/// 施肥方式枚举
enum ApplicationMethod {
  soilIncorporation('Soil incorporation'),
  rootDrenching('Root Drenching'),
  foliarSpraying('Foliar Spraying');

  const ApplicationMethod(this.displayName);
  final String displayName;
}

/// 病虫害类型枚举
enum PestDiseaseType {
  aphids('Aphids'),
  redSpiderMites('Red Spider Mites'),
  powderyMildew('Powdery Mildew'),
  rootRot('Root Rot');

  const PestDiseaseType(this.displayName);
  final String displayName;
}

/// 发病部位枚举
enum OnsetSite {
  undersideOfLeaf('The underside of the leaf'),
  baseOfStem('The Base Of The Stem'),
  rootSystem('The Root System');

  const OnsetSite(this.displayName);
  final String displayName;
}

/// 植物记录模型
/// 使用Equatable实现相等性比较
class PlantRecordModel extends Equatable {
  /// 记录ID
  final String id;

  /// 记录日期
  final DateTime recordDate;

  /// 植物图片路径列表
  final List<String> plantImages;

  /// 植物高度（厘米）
  final double? plantHeight;

  /// 叶片总数
  final int? totalBlades;

  /// 健康叶片数
  final int? healthyLeaves;

  /// 黄叶数
  final int? yellowedLeaves;

  /// 总浇水量（毫升）
  final double? totalWateringVolume;

  /// 浇水方式
  final WateringMethod? wateringMethod;

  /// 施肥率
  final double? applicationRate;

  /// 肥料类型
  final FertilizerType? fertilizerType;

  /// 施肥方式
  final ApplicationMethod? applicationMethod;

  /// 花朵总数
  final int? totalBlooms;

  /// 半开花朵数
  final int? halfOpenFlowers;

  /// 枯萎花朵数
  final int? wiltedFlowers;

  /// 病虫害类型
  final PestDiseaseType? pestDiseaseType;

  /// 发病部位
  final OnsetSite? onsetSite;

  /// 备注
  final String? notes;

  const PlantRecordModel({
    required this.id,
    required this.recordDate,
    this.plantImages = const [],
    this.plantHeight,
    this.totalBlades,
    this.healthyLeaves,
    this.yellowedLeaves,
    this.totalWateringVolume,
    this.wateringMethod,
    this.applicationRate,
    this.fertilizerType,
    this.applicationMethod,
    this.totalBlooms,
    this.halfOpenFlowers,
    this.wiltedFlowers,
    this.pestDiseaseType,
    this.onsetSite,
    this.notes,
  });

  /// 复制并修改部分属性
  PlantRecordModel copyWith({
    String? id,
    DateTime? recordDate,
    List<String>? plantImages,
    double? plantHeight,
    int? totalBlades,
    int? healthyLeaves,
    int? yellowedLeaves,
    double? totalWateringVolume,
    WateringMethod? wateringMethod,
    double? applicationRate,
    FertilizerType? fertilizerType,
    ApplicationMethod? applicationMethod,
    int? totalBlooms,
    int? halfOpenFlowers,
    int? wiltedFlowers,
    PestDiseaseType? pestDiseaseType,
    OnsetSite? onsetSite,
    String? notes,
  }) {
    return PlantRecordModel(
      id: id ?? this.id,
      recordDate: recordDate ?? this.recordDate,
      plantImages: plantImages ?? this.plantImages,
      plantHeight: plantHeight ?? this.plantHeight,
      totalBlades: totalBlades ?? this.totalBlades,
      healthyLeaves: healthyLeaves ?? this.healthyLeaves,
      yellowedLeaves: yellowedLeaves ?? this.yellowedLeaves,
      totalWateringVolume: totalWateringVolume ?? this.totalWateringVolume,
      wateringMethod: wateringMethod ?? this.wateringMethod,
      applicationRate: applicationRate ?? this.applicationRate,
      fertilizerType: fertilizerType ?? this.fertilizerType,
      applicationMethod: applicationMethod ?? this.applicationMethod,
      totalBlooms: totalBlooms ?? this.totalBlooms,
      halfOpenFlowers: halfOpenFlowers ?? this.halfOpenFlowers,
      wiltedFlowers: wiltedFlowers ?? this.wiltedFlowers,
      pestDiseaseType: pestDiseaseType ?? this.pestDiseaseType,
      onsetSite: onsetSite ?? this.onsetSite,
      notes: notes ?? this.notes,
    );
  }

  @override
  List<Object?> get props => [
    id,
    recordDate,
    plantImages,
    plantHeight,
    totalBlades,
    healthyLeaves,
    yellowedLeaves,
    totalWateringVolume,
    wateringMethod,
    applicationRate,
    fertilizerType,
    applicationMethod,
    totalBlooms,
    halfOpenFlowers,
    wiltedFlowers,
    pestDiseaseType,
    onsetSite,
    notes,
  ];

  @override
  String toString() {
    return 'PlantRecordModel(id: $id, recordDate: $recordDate, plantHeight: $plantHeight)';
  }
}
